package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.CircuitTypeHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.NetWorkVersionAttrHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.NodeTypeAHandler;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author wanghl386
 * @version 1.0
 * @date 2021/5/25 19:57
 */

@Service
@AttrHandler(CircuitTypeHandler.class)
public class NodeTypeALinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    /**
     * 承载电路类型
     */
    private static final String CIRCUIT_TYPE = "210004190";

    /**
     * 以太网类型
     */
    private static final String ETHERNET = "110007436";
    /**
     * 数字电路
     */
    private static final String DIGITAL_CIRCUIT = "1_0000229";

    /**
     * 固定带宽
     */
    private static final String FIXED_BAND_WIDTH = "210004224";
    /**
     * 基础带宽
     */
    private static final String BASE_BAND_WIDTH = "200001818";

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        if (CIRCUIT_TYPE.equals(attr.getFieldName())) {
            // a端节点类型
            KiteAttr aModel = inst.getAttr("200003132");
            KiteAttr zModel = inst.getAttr("200003136");
            // 以太网
            if (ETHERNET.equals(attr.getValue())) {
                aModel.setShowType("D");
                zModel.setShowType("D");
                // 数字电路的时候，固定带宽只显示部分值，whl新加 以太网电路的时候需要把值显示全，直接复制基础带宽的下拉框值
                inst.getAttr(FIXED_BAND_WIDTH).setAttrValues(inst.getAttr(BASE_BAND_WIDTH).getAttrValues());
            } else if (DIGITAL_CIRCUIT.equals(attr.getValue())) {
                // 数字电路
                aModel.setShowType("H");
                zModel.setShowType("H");
                // 数字电路的时候，固定带宽只显示部分值，whl新加
                String fixedBandWidth = "1_0000014,1_0000015,1_0000033,1_0000036,1_0000043,1_0000048,1_0000050,1_0000065,1_0000104,1_0000105";
                String[] split = fixedBandWidth.split(",");
                List<KiteAttrValue> list = inst.getAttr(FIXED_BAND_WIDTH).getAttrValues().stream().filter(kiteAttrValue -> Arrays.stream(split).anyMatch(str -> str.equals(kiteAttrValue.getAttrValue()))).collect(Collectors.toList());
                inst.getAttr(FIXED_BAND_WIDTH).setAttrValues(list);
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
